<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>来款手动核销 管理【未启用支付表】</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">资金编号</div>
                    <div class="field">
                        <input name="code" id="code" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">收款账号</div>
                    <div class="field">
                        <input name="acceptCode" id="acceptCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <%--<div class="fieldBox">
                    <div class="label">收款户名</div>
                    <div class="field">
                        <input name="acceptName" id="acceptName" type="text" class="ui-textbox" value="">
                    </div>
                </div>--%>
                <div class="fieldBox">
                    <div class="label">来款账号</div>
                    <div class="field">
                        <input name="comeCode" id="comeCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">来款户名</div>
                    <div class="field">
                        <input name="comeName" id="comeName" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">来款金额</div>
                    <div class="field">
                        <input ligerui="width: 82" name="amountMin" id="amountMin" type="text" class="ui-textbox" value="">
                        -
                        <input ligerui="width: 82" name="amountMax" id="amountMax" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">实际到账日</div>
                    <div class="field">
                        <input ligerui="width: 82" name="acceptActualDateMin" id="acceptActualDateMin" type="text" class="ui-datepicker" value="">
                        -
                        <input ligerui="width: 82" name="acceptActualDateMax" id="acceptActualDateMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">导入日期</div>
                    <div class="field">
                        <input ligerui="width: 82" name="crtTmMin" id="crtTmMin" type="text" class="ui-datepicker" value="">
                        -
                        <input ligerui="width: 82" name="crtTmMax" id="crtTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                 <div class="fieldBox ">
                    <div class="label">资金类型</div>
                    <div class="field">
                        <select name="capTypCd" id="capTypCd" data-value=" ">
                            <option value=" " checked>请选择</option>
                            <c:forEach items="${fundConfirmByListPage}" var="kv">
                                <option value="${kv.key}">${kv.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <c:if test="${type==2}">
                    <div class="fieldBox">
                        <div class="label">支付表号</div>
                        <div class="field">
                            <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                        </div>
                    </div>
                </c:if>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>
                    <c:if test="${type==1}">
                        <span id="confirmBtn" class="sq-button sq-button-round">认款/重置认款</span>
                        <span id="decomBtn" class="sq-button sq-button-round">分解</span>
                    </c:if>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback=null;
    $(function () {
    	//加载资金类型
        var fundConfirmByListPageListJSON = [];
        <c:if test="${not empty fundConfirmByListPageListJSON}">
        fundConfirmByListPageListJSON = ${fundConfirmByListPageListJSON};
        </c:if>
        var columns_hide = true;
        var type_grid = '${type}';
        if (type_grid == 2) {
            columns_hide = false
        }
    	// fundPid=1 代表显示子资金
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capFund/initList.do',
            parms:{type:'${type}',fundPid:1},
            method: 'get',
            columns: [
                {display: '资金编号', name: 'code', minWidth: 130, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '<a style="cursor: pointer;" onclick="qyDecompose('+rowdata.id+');">'+rowdata.code+'</a>'
                    }
                },
                <c:if test="${type==1}">
                {display: '资金状态', name: 'fundStatusCdNm', width: 80, align: 'center', enabledSort: false},
                </c:if>
                {display: '收款账号', name: 'acceptCode', minWidth: 100, align: 'center', enabledSort: false},
                {display: '收款账户', name: 'acceptName', minWidth: 100, align: 'center', enabledSort: false},
                {display: '来款账号', name: 'comeCode', minWidth: 100, align: 'left', enabledSort: false},
                {display: '来款户名', name: 'comeName', minWidth: 100, align: 'center', enabledSort: false},
                {display: '收到金额(元)', name: 'amount', width: 90, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.amount/100);
                    }
                },
                {display: '客户名称', name: 'cstId', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        var comeName = rowdata.comeName;
                        if(comeName){
                            comeName=comeName.replace(/\ +/g,"");//去掉空格
                            comeName=comeName.replace(/[ ]/g,"");//去掉空格
                            comeName=comeName.replace(/[\r\n]/g,"");//去掉回车换行
                        }
                        if(rowdata.cstId){
                            return '<a style="cursor: pointer;" onclick="confirmFund('+rowdata.id+',\''+comeName+'\',\''+rowdata.comeCode+'\');"></i>'+rowdata.cstNm+'</a>'
                        }else{
                            return '<a style="cursor: pointer;" onclick="confirmFund('+rowdata.id+',\''+comeName+'\',\''+rowdata.comeCode+'\');"></i>未认款</a>'
                        }
                    }
                },
                {display: '实际到账日期', name: 'acceptActualDate', width: 130, align: 'center', enabledSort: false,render:renderDate},
                {display: '导入日期', name: 'crtTm', width: 130, align: 'center', enabledSort: true,render:renderDate},
                {display: '认款人', name: 'identifyOperatorNm', width: 100, align: 'center', enabledSort: false},
                {
                    display: '分解时间',
                    name: 'decomposeTime',
                    width: 130,
                    align: 'center',
                    hide: columns_hide,
                    enabledSort: false,
                    render: renderDate
                },
                {display: '摘要', name: 'docketRem', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (value) {
                            var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.docketRem + '">' + rowdata.docketRem + '</span>';
                            return h;
                        }
                    }
                },
                {
                    display: '资金类型', name: 'capTypCd', width: 150,
                    editor: {
                        type: 'select',
                        data: fundConfirmByListPageListJSON,
                        valueField: 'key',
                        textField: 'value'
                    },
                    valueField: 'capTypCd',
                    textField: 'capTypCdNm',
                    render: function (item) {
                        if (StringUtils.isEmpty(item.capTypCd)) {
                            item.capTypCdNm = "请选择资金类型！";
                            return '请选择资金类型<i class="ico_flasher"></i>';
                        } else {
                            return item.capTypCdNm
                        }
                    }
                },
                {
                    display: '操作', name: '', minWidth: 150, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        var action = '';
                        action += '<a class="sq-button-hasicon" href="javascript:remarkFund(' + rowdata.id + ',\'' + rowdata.comeName + '\');"><i class="sqBtnIco_4"></i>添加备注</a>';
                        action += '<a class="sq-button-hasicon" href="javascript:frozenFund(' + rowdata.id + ');">冻结</a>';
                        return action;
                    }
                }
                
                /*{display: '来款机构', name: 'fundBelongOrgCdNm', minWidth: 100, align: 'center', enabledSort: false},*/
                /*{display: '摘要', name: 'docketRem', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if(!rowdata.docketRem){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.docketRem + '">' + rowdata.docketRem + '</span>';
                        }
                    }
                },*/
                /*{display: '操作', name: '', minWidth: 100, align: 'center', enabledSort: false,
                    render:function (rowdata,rowindex,value) {
                        if(rowdata.cstId>0&&rowdata.availableAmount>0){
                            return '<a style="cursor: pointer;" onclick="decomFund('+rowdata.id+');">分解</a>';
                        }
                    }
                },*/
                ],
                onBeforeSubmitEdit: function (e) {
                    //验证编辑器结果是否通过 [介于编辑后未提交之前  原始数据与新数据对比]
                    if (e.column.name == "capTypCd") {
                        //原始值与选中值判断是否一致
                        //debugger;
                        if (StringUtils.isEmpty(e.value) || e.record.capTypCd == e.value) {
                            $.ligerDialog.SQalert({content: LogUtils.LOG_CAP_FUND_TYPE_LOG, SQ_type: "warning"});
                        } else {
                            onModify(e.record.id, e.value);
                        }
                    }
                },
            enabledEdit: true,
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            isSingleCheck:true,
            rownumbers: true,
            allowUnSelectRow: true
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });
        
        
        //修改类型
        function onModify(id, value) {
            //如果客户恶意选中 这里将拦截
            if (StringUtils.isEmpty(value)) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_OPERATE_FAIL, SQ_type: "error"});
            }
            $.ajax({
                type: 'GET',
                dataType: 'json',
                url: '<%=path%>/capital/capFund/modifyFundType.do?id=' + id + '&value=' + value,
                success: function (msg) {
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload($('.pcontrol input', grid.toolbar).val());//加载到当前页
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
        
        
  

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": " "
            });
        });

        /* 认款/重置认款 */
        $("#confirmBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length != 1){
                $.ligerDialog.SQalert({content:LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if(selectedRows[0].fundSourcesCd != null && selectedRows[0].fundSourcesCd == '7') {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CAP_FUND_SOURCE_LOG, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;//资金ID
            var _cstId = selectedRows[0].cstId;//客户ID
            var _cstNm=selectedRows[0].comeName;//来款账户名称
            if(_cstNm){
                _cstNm=_cstNm.replace(/\ +/g,"");//去掉空格
                _cstNm=_cstNm.replace(/[ ]/g,"");//去掉空格
                _cstNm=_cstNm.replace(/[\r\n]/g,"");//去掉回车换行
            }
            if(!_cstId){//认款
                $.ligerDialog.open({
                    cls: 'noBorder_Dialog',
                    width: 750,
                    height: 500,
                    title: '认款列表',
                    url:'<%=path%>/capital/capFund/toFundConfirmPage.do?id='+_id+'&cstNm='+_cstNm
                });
            }else{//重置认款
                $.ligerDialog.confirm("确定重置为\"未认款\"吗？", function (flag) {
                    if(flag == false)return;
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {id: _id,cstId:"",cstNm:""},
                        url: '<%=path%>/capital/capFund/confirmFund.do',
                        beforeSend: function () {
                            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type: "waitting"});
                        },
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success == 1) {
                                top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                grid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                            }
                        }
                    });
                });
            }
        });

        /* 分解 */
        $("#decomBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if(selectedRows.length != 1){
                $.ligerDialog.SQalert({content:LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if(selectedRows[0].fundSourcesCd != null && selectedRows[0].fundSourcesCd == '7') {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CAP_FUND_SOURCE_LOG, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;//资金ID
            var _cstId = selectedRows[0].cstId;//客户ID
            //判断是否已认款
            if(!_cstId){
                $.ligerDialog.SQalert({content: "该笔资金尚未认款，请先认款",SQ_type: "warning",
                    SQ_buttonYesText : "确定",
                    SQ_showButtons : true,
                });
                return;
            }else{
                if(selectedRows[0].availableAmount<=0){
                    $.ligerDialog.SQalert({content: "该笔资金没有可分解的金额",SQ_type: "warning"});
                    return;
                }
            }

            Add_navTab('CapFundDecomposeAbnormal_'+_id, "资金分解【未启用支付表】", '<%=path%>/capital/capFund/toDecomposePageAbnormal.do?id='+_id, callback);

            //验证资金可否分解
            /*var _ids = [_id];
            $.ajax({
                url: '<%=path%>/capital/capFund/validateDecomFund.do',
                type: 'post',
                data:{ids: JSON.stringify(_ids)},
                dataType: 'json',
                success: function (msg) {
                    if (msg.success == 1) {
                        Add_navTab('CapFundDecompose_'+_id, "资金分解", '<%=path%>/capital/capFund/toDecomposePage.do?id='+_id, callback);
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error",SQ_showButtons : true,});
                    }
                }
            });*/

        });

        callback = function () {
            grid.reload();
        };

    });

    //备注
    function remarkFund(id, name) {
        var params = "id=" + id;
   	 $.ligerDialog.SQopen({
           cls: 'no_Modify_Fund_Rem',
           width: 850,
           height: 450,
           title: '添加资金转出记录',
           url:'<%=path%>/capital/capFundRemLog/toListPage.do?' + params
       });
    }
    
    //资金分解
    function decomFund(_id){
        Add_navTab('CapFundDecomposeAbnormal_'+_id, "资金分解【未启用支付表】", '<%=path%>/capital/capFund/toDecomposePageAbnormal.do?id='+_id, callback);
    }

    //查看分解单
    function qyDecompose(id){
        Add_navTab('toDecomDtlPage_'+id, "分解单查看", '<%=path%>/capital/capFund/toDecomDtlPage.do?fundId='+id, callback);
    }

    //认款
    function confirmFund(id,comeName,comeCode){
        $.ligerDialog.open({
            width: 750,
            height: 500,
            title: '认款列表',
            url:'<%=path%>/capital/capFund/toFundConfirmPage.do?id='+id+'&cstNm='+comeName
        });
    }

    //格式化时间
    function renderDate(rowdata, rowindex, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    // 冻结事件
    function frozenFund(id){
        $.ligerDialog.confirm("确定要冻结吗？", function (flag) {
            if(flag == false)return;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {capFundId: id},
                url: '<%=path%>/capital/capFund/frozenCapital.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error",SQ_showButtons: true});
                    }
                }
            });
        });
    }
</script>

</body>
</html>
